<template>
  <div class="mb20">
    <el-row :gutter="20">
      <el-col :span="6">
        <div class="grid-content ep-bg-purple">
          <div class="grid-content-top">
            <div class="grid-content-title">
              <div>在线</div>
              <el-tag type="success">实时</el-tag>
            </div>
          </div>
          <div class="grid-content-bottom">
            <div class="grid-content-items">
              <div>总数（项目）：</div>
              <div style="color: #67c23a;font-weight: bold;font-size: 20px;">{{resData ? resData.onlineCount : 0}}</div>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content ep-bg-purple">
          <div class="grid-content-top">
            <div class="grid-content-title">
              <div>离线</div>
              <el-tag type="danger">实时</el-tag>
            </div>
          </div>
          <div class="grid-content-bottom">
            <div class="grid-content-items">
              <div>总数（项目）：</div>
              <div style="color: #f56c6c;font-weight: bold;font-size: 20px;">{{resData ? resData.offlineCount : 0}}</div>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content ep-bg-purple">
          <div class="grid-content-top">
            <div class="grid-content-title">
              <div>已启动</div>
              <el-tag type="success">实时</el-tag>
            </div>
          </div>
          <div class="grid-content-bottom">
            <div class="grid-content-items">
              <div>总数（项目）：</div>
              <div style="color: #67c23a;font-weight: bold;font-size: 20px;">{{resData ? resData.startedCount : 0}}</div>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content ep-bg-purple">
          <div class="grid-content-top">
            <div class="grid-content-title">
              <div>未启动</div>
              <el-tag type="danger">实时</el-tag>
            </div>
          </div>
          <div class="grid-content-bottom">
            <div class="grid-content-items">
              <div>总数（项目）：</div>
              <div style="color: #f56c6c;font-weight: bold;font-size: 20px;">{{resData ? resData.notStartedCount : 0}}
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="statistics">
  import { queryingStatistics } from "@/api/deviceManage/index.js";
  const { proxy } = getCurrentInstance();
  const props = defineProps({
    project: {
      type: String,
      default: '',
    },
    selectDate: {
      type: String,
      default: '',
    },
    state: {
      type: Number,
      default: 0,
    },
  });
  watch(() => props.state, (newVal, oldVal) => {
    if (newVal !== oldVal) {
      openView({ project: props.project, selectDate: props.selectDate });
    }
  }, { deep: true, immediate: true });
  const resData = ref(null);
  function GetStatisticsAPi(row) {
    queryingStatistics(row).then(response => {
      resData.value = response.data;
    });
  };
  function openView() {
    // console.log(props.project, 'ABCDEFG-props.formData');
    GetStatisticsAPi({ project: props.project, selectDate: props.selectDate });
  }
  // openView();
  defineExpose({
    // openDialog
  });
</script>
<style lang="scss" scoped>
  .el-row {
    margin-bottom: 20px;
  }

  .el-row:last-child {
    margin-bottom: 0;
  }

  .el-col {
    border-radius: 4px;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 120px;
    border: 1px solid #f0f0f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* background: yellowgreen; */
    /* padding: 12px; */
  }

  .grid-content-top {
    display: flex;
    justify-content: center;
    flex-direction: column;
    min-height: 56px;
    margin-bottom: -1px;
    padding: 0 24px;
    color: rgba(0, 0, 0, 0.88);
    font-weight: 600;
    font-size: 16px;
    border-bottom: 1px solid #f0f0f0;
    border-radius: 8px 8px 0 0;
  }

  .grid-content-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .grid-content-bottom {
    padding: 12px;
  }

  .grid-content-item {
    padding-top: 1rem;
    padding-bottom: 1rem;
    padding-left: 1rem;
    padding-right: 1rem;
    display: flex;
    align-items:
      center;
    justify-content: space-between;
  }

  .grid-content-items {
    padding: 0.5rem;
    display: flex;
    align-items: center;
    padding-left: 1rem;
    padding-right: 1rem;
    justify-content: space-between;
  }

  /*
  :deep() {
    .el-dialog {
      pointer-events: auto !important;
      display: flex;
      flex-direction: column;
      margin: 0 !important;
      position: absolute;
      top: 40%;
      left: 50%;
      transform: translate(-50%, -40%);
      max-height: calc(100% - 60px);
      max-width: calc(100% - 30px);
    }

    .el-dialog .el-dialog__body {
      flex: 1;
      overflow: auto;
    }
  } */
</style>
